
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>分类维护</title>
    <link href="/static/devtools30/layui/css/layui.css" rel="stylesheet" />
    <link href="/static/devtools30/css/devindexbase.css" rel="stylesheet" />
    <script src="/static/devtools30/js/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/devtoolCommon.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui/layui.all.js" type="text/javascript"></script>
    <style>
        /*按钮大小*/

        .layui-btn {
            height: 26px;
            line-height: 26px;
            font-size: 11px;
        }
        /*顶部容器*/
        .topwrap {
            height: 32px;
            line-height: 32px;
            border: 1px solid #F7F7F7;
            padding: 0 5px;
            margin: 0 2px;
        }
        /*按钮组边框*/
        .layui-btn-group .layui-btn {
            border-left: 1px solid rgba(255, 255, 255, .5)!important;
        }
        .layui-btn-group .layui-btn-primary:first-child {
            border-left: 1px solid #c9c9c9!important;
        }

        /*table表格边距*/
        .layui-table,
        .layui-table-view {
            margin: 0;
        }
    </style>

</head>
<body>
<div>
    <div class="flex flex-jusity-end flex-align-center topwrap backgroundf">
        <div class="layui-btn-group btnwrap">
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='add'>新增</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='edit'>修改</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='del'>删除</button>
        </div>
    </div>
    <div style="padding: 2px;width: 100%;background: #F7F7F7;">
        <div class="backgroundf">
            <table id="mygrid" lay-filter="mygrid"></table>
        </div>
    </div>
</div>
</body>
<script>
    var height = dlCommon.getWinHeight();
    var width=dlCommon.getWinWidth();
    var selTableId="";

    $(function(){
        initGrid();

        initEvent();
        loadData();
    })

    function loadData(){
        layui.table.reload("mygrid",{
            url:"/DevtZbobjInfoEntityController/getAll",
            loading:true,

        });
    }
    function initGrid(){
        layui.table.render({
            elem: '#mygrid'
            ,height: height-50
            ,width:width-10
            ,size: 'sm' //小尺寸的表格
            ,page: false //开启分页
            ,cols: [
            [ //表头
                {field: 'zbobjname', title: '指标对象名称', width:'20%', fixed: 'left'}
                ,{field: 'zbobjcode', title: '指标对象代码'}
            ]]
        });
    }
    function initEvent(){
        //增删改点击方法
        $('.btnwrap>button').on('click',function(){
            var names = $(this)[0].name;
            //新增
            if(names == 'add'){
                dlCommon.layeropen(680,500,"新增",'/V_DevtZbobjInfoEntityController/edit');
                return;
            }
            if(!selTableId){
                dlCommon.layerInfo('请选择数据');
                return;
            }
            //修改
            if(names == 'edit'){
                dlCommon.layeropen(680,500,"修改",'/V_DevtZbobjInfoEntityController/edit?id='+selTableId);

            }
            if(names == 'del'){
                //删除
                del(selTableId);
            }
        })

        dlCommon.layerTableOn('mygrid', function(obj){

            selTableId=obj.data.id;

        });
    }
    function del(id) {
        if(!id){
            return;
        }
        dlCommon.layerConfirm("是否确定删除该指标对象？",function(){
            dlCommon.getJSON("/DevtZbobjInfoEntityController/delete",{id:id},function(res){
                if(!res.success){
                    dlCommon.layerError(res.msg);
                    return;
                }
                loadData();
            })
        })

    }
</script>
</html>
